package com.ruoyi.gams.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.gams.device.led.LEDSender2010;
import com.ruoyi.gams.device.led.ScreenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.gams.mapper.GamsWindowScreenMapper;
import com.ruoyi.gams.domain.GamsWindowScreen;
import com.ruoyi.gams.service.IGamsWindowScreenService;

/**
 * 窗口屏Service业务层处理
 *
 * @author ruoyi
 */
@Slf4j
@Service
public class GamsWindowScreenServiceImpl implements IGamsWindowScreenService
{
    @Autowired
    private GamsWindowScreenMapper gamsWindowScreenMapper;

    @Autowired
    private ScreenService screenService;

    /**
     * 查询窗口屏
     *
     * @param id 窗口屏主键
     * @return 窗口屏
     */
    @Override
    public GamsWindowScreen selectGamsWindowScreenById(Integer id)
    {
        return gamsWindowScreenMapper.selectGamsWindowScreenById(id);
    }

    /**
     * 查询窗口屏列表
     *
     * @param gamsWindowScreen 窗口屏
     * @return 窗口屏
     */
    @Override
    public List<GamsWindowScreen> selectGamsWindowScreenList(GamsWindowScreen gamsWindowScreen)
    {
        return gamsWindowScreenMapper.selectGamsWindowScreenList(gamsWindowScreen);
    }

    /**
     * 新增窗口屏
     *
     * @param gamsWindowScreen 窗口屏
     * @return 结果
     */
    @Override
    public int insertGamsWindowScreen(GamsWindowScreen gamsWindowScreen)
    {
        gamsWindowScreen.setCreateTime(DateUtils.getNowDate());
        return gamsWindowScreenMapper.insertGamsWindowScreen(gamsWindowScreen);
    }

    /**
     * 修改窗口屏
     *
     * @param gamsWindowScreen 窗口屏
     * @return 结果
     */
    @Override
    public int updateGamsWindowScreen(GamsWindowScreen gamsWindowScreen)
    {
        gamsWindowScreen.setUpdateTime(DateUtils.getNowDate());
        return gamsWindowScreenMapper.updateGamsWindowScreen(gamsWindowScreen);
    }

    /**
     * 批量删除窗口屏
     *
     * @param ids 需要删除的窗口屏主键
     * @return 结果
     */
    @Override
    public int deleteGamsWindowScreenByIds(Integer[] ids)
    {
        return gamsWindowScreenMapper.deleteGamsWindowScreenByIds(ids);
    }

    /**
     * 删除窗口屏信息
     *
     * @param id 窗口屏主键
     * @return 结果
     */
    @Override
    public int deleteGamsWindowScreenById(Integer id)
    {
        return gamsWindowScreenMapper.deleteGamsWindowScreenById(id);
    }

    @Override
    public void updateScreenInfo()
    {
        List<GamsWindowScreen> list = gamsWindowScreenMapper.selectGamsWindowScreenList(new GamsWindowScreen());
        log.info("发现控制卡：" + list.size());
        list.forEach(e ->
        {
            HttpRequestUtils.httpPost("http://localhost:8083/ruoyi-socket/device-api/refreshWindowScreen?windowScreenId=" + e.getId(), "");
            try
            {
                Thread.sleep(10000);
            } catch (InterruptedException interruptedException)
            {
                interruptedException.printStackTrace();
            }
        });
    }

    public static void main(String[] args)
    {
        HttpRequestUtils.httpPost("http://localhost:8083/ruoyi-socket/device-api/refreshWindowScreen?windowScreenId=" + 12, "");
    }
}
